﻿using System;
using Windows.ApplicationModel.DataTransfer;
using Windows.Foundation;

namespace Smile.Mvvm.Service
{
    /// <summary>Service wich manage sharing on social networks, mails and SMS.</summary>
    public class ShareService:IShareService
    {
        // @Public
        public void ShareLink(string uriString, string title = "", string message = "")
        {
            ShareLink(new Uri(uriString, UriKind.Absolute), title, message);
        }

        public void ShareLink(Uri uri, string title = "", string message = "")
        {
            _linkData = new ShareLinkData(uri, title, message);
            var dataTransferManager = DataTransferManager.GetForCurrentView();
            dataTransferManager.DataRequested += ShareLinkHandler;
        }

        public void ShareByMail(
            string subject, 
            string message, 
            string to = "", 
            string cc = "", 
            string bcc = "")
        {
        }

        // @Private
        ShareLinkData _linkData;

        void ShareLinkHandler(DataTransferManager sender, DataRequestedEventArgs args)
        {
            if (_linkData != null)
            {
                DataRequest request = args.Request;
                request.Data.Properties.Title = _linkData.Title;
                request.Data.Properties.Description = _linkData.Description;
                request.Data.SetUri(_linkData.Uri);
            }
        }
    }
}
